package com.yanfan.energy.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.energy.domain.ConfigurationCop;
import com.yanfan.energy.service.ConfigurationCopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot/cop")
@Api(tags = "cop配置")
public class ConfigurationCopController extends BaseController {
    @Autowired
    private ConfigurationCopService configurationCopService;

    /**
     * 查询cop配置列表
     */
    @GetMapping("/list")
    @ApiOperation("查询cop配置列表")
    public TableDataInfo list(ConfigurationCop configurationCop) {
        startPage();
        List<ConfigurationCop> list = configurationCopService.selectConfigurationCopList(configurationCop);
        return getDataTable(list);
    }

    /**
     * 获取cop配置详细信息
     */
    @GetMapping(value = "/{copId}")
    @ApiOperation("获取cop配置详细信息")
    public AjaxResult getInfo(@PathVariable("copId") Long copId) {
        return success(configurationCopService.selectConfigurationCopByCopId(copId));
    }

    /**
     * 新增cop配置
     */
    @Log(title = "cop配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增cop配置")
    public AjaxResult add(@RequestBody ConfigurationCop configurationCop) {
        return toAjax(configurationCopService.insertConfigurationCop(configurationCop));
    }

    /**
     * 修改cop配置
     */
    @Log(title = "cop配置", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改cop配置")
    public AjaxResult edit(@RequestBody ConfigurationCop configurationCop) {
        return toAjax(configurationCopService.updateConfigurationCop(configurationCop));
    }

    /**
     * 删除cop配置
     */
    @Log(title = "cop配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{copIds}")
    @ApiOperation("删除cop配置")
    public AjaxResult remove(@PathVariable Long copIds) {
        return toAjax(configurationCopService.deleteConfigurationCopByCopId(copIds));
    }
}
